package com.linrui.org.controller;

import com.linrui.org.service.IShopAuditLogService;
import com.linrui.org.domain.ShopAuditLog;
import com.linrui.org.query.ShopAuditLogQuery;
import com.linrui.basic.utils.AjaxResult;
import com.linrui.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;

@RestController
@RequestMapping("/shopAuditLog")
@Api(value = "管理controller",description = "管理controller")
public class ShopAuditLogController {
    @Autowired
    public IShopAuditLogService shopAuditLogService;


    /**
     * 保存和修改公用的
     * @param shopAuditLog  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    @ApiOperation(value = "保存")
    public AjaxResult save(@RequestBody ShopAuditLog shopAuditLog){
        try {
            if( shopAuditLog.getId()!=null)
                shopAuditLogService.update(shopAuditLog);
            else
                shopAuditLogService.add(shopAuditLog);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("保存失败！"+e.getMessage());
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    @ApiOperation(value = "删除")
    public AjaxResult removeById(@PathVariable("id") Long id){
        try {
            shopAuditLogService.removeById(id);
            return AjaxResult.me();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.me().setMessage("删除失败！"+e.getMessage());
        }
    }
    // 批量操作 @TODO
    @PatchMapping
    @ApiOperation(value = "批量删除")
    public AjaxResult batchRemove(@RequestBody List<Long> ids){
        try {
                shopAuditLogService.batchRemove(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("查询失败!"+e.getMessage());
        }
    }
    //获取用户
    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情")
    public AjaxResult getById(@PathVariable("id")Long id)
    {
        try {
            ShopAuditLog shopAuditLog = shopAuditLogService.getById(id);
            return AjaxResult.me().setResult(shopAuditLog);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("获取失败！"+e.getMessage());
        }
    }


    /**
    * 查看所有的信息
    * @return
    */
    @GetMapping
    @ApiOperation(value = "查询全部")
    public AjaxResult getAll(){

        try {
            List< ShopAuditLog> list = shopAuditLogService.getAll();
            return AjaxResult.me().setResult(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("获取所有失败！"+e.getMessage());
        }
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    @ApiOperation(value = "分页查询")
    public AjaxResult pageList(@RequestBody ShopAuditLogQuery query)
    {
        try {
            PageList<ShopAuditLog> pageList = shopAuditLogService.pageList(query);
            return AjaxResult.me().setResult(pageList);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("获取数据失败！"+e.getMessage());
        }
    }
}
